#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Description: 
@Project    ：ImportDataCheck 
@File       ：mytextedit.py
@IDE        ：PyCharm 
@Author     ：YLF
@Email      ：76332706@163.com
@Date       ：2020/12/23 14:57 
"""
from PyQt5 import QtGui
from PyQt5.QtWidgets import QTextEdit


class MyTextEdit(QTextEdit):
    def __init__(self, parent):
        super(MyTextEdit, self).__init__(parent)
        self.setAcceptDrops(True)
        self.filetype = ['xls', 'xlsx']

    # def dragEnterEvent(self, e: QtGui.QDragEnterEvent) -> None:
    #     if e.mimeData().text().split(".")[-1] in self.filetype:
    #         e.accept()
    #     else:
    #         print("error")
    #         e.ignore()

    def dropEvent(self, e: QtGui.QDropEvent) -> None:
        _file_list = e.mimeData().text().split('\n')
        for _e in _file_list:
            if _e.split(".")[-1] in self.filetype:
                path = e.mimeData().text().replace('file:///', '')
                path = path.replace('/', '\\')
                if path not in self.toPlainText():
                    self.append(path)
